home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tools / utils / twtcp122 / pktdrv / pktlance / pktqueue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-25  |  1.6 KB  |  87 lines

  1. #include "lancemem.h"
  2. #include "pktqueue.h"
  3. #include <tos.h>
  4.  
  5. #ifndef NULL
  6. #define NULL (void *)0L
  7. #endif
  8.  
  9. #define FALSE 0
  10. #define TRUE  1 
  11.  
  12. #define DEBUGPKT
  13. #define noDEBUG
  14.  
  15. short p_intstat;
  16. extern long p_disint(void);
  17. extern long p_enabint(void);
  18.  
  19.  
  20. PKTPOOL *p_init(int npkt,PKTPOOL *p_pool,PKTBUF *p_buf)
  21. {
  22. register int i;
  23.  
  24.     if(!p_pool) return(NULL);
  25.     p_pool->p_get = p_pool->p_put = 0;
  26.     p_pool->p_nbuf = npkt;
  27.     for(i=0; i<npkt; i++)
  28.     {
  29.         p_pool->p_tab[i].p_occupied = FALSE;
  30.         p_pool->p_tab[i].p_pkt = p_buf+i;
  31.     }
  32.     return(p_pool);
  33. }
  34.  
  35. PKTBUF *ap_getpkt(u_short protocol, PKTPOOL *p_pool)
  36. {
  37. PKTBUF *pkt;
  38.     p_disint();
  39.     pkt=p_getpkt(protocol,p_pool);
  40.     p_enabint();
  41.     return(pkt);
  42. }
  43.  
  44.  
  45. PKTBUF *p_getpkt(u_short protocol, PKTPOOL *p_pool)
  46. {
  47. register int i;
  48.  
  49.     if(!p_pool) return(NULL);
  50.     i = p_pool->p_get;
  51.     if(p_pool->p_tab[i].p_occupied) return(NULL);
  52.     p_pool->p_get++;
  53.     if(p_pool->p_get >= p_pool->p_nbuf) p_pool->p_get = 0;
  54.     p_pool->p_tab[i].p_occupied = protocol;
  55.     return(p_pool->p_tab[i].p_pkt);
  56. }
  57.  
  58. int ap_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
  59. {
  60. int r;
  61.     Supexec(p_disint);
  62.     r=p_putpkt(p_pool,pkt);
  63.     Supexec(p_enabint);
  64.     return(r);
  65. }
  66.  
  67.  
  68. int p_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
  69. {
  70. register int i;
  71.  
  72.     if(!p_pool) return(FALSE);
  73.     i = p_pool->p_put;
  74.     if(!p_pool->p_tab[i].p_occupied)
  75.     {
  76. #ifdef DEBUGPKT
  77.         Cconws("Packet already in queue\r\n");
  78. #endif
  79.         return(FALSE);
  80.     }
  81.     p_pool->p_put++;
  82.     if(p_pool->p_put >= p_pool->p_nbuf) p_pool->p_put = 0;
  83.     p_pool->p_tab[i].p_pkt = pkt;
  84.     p_pool->p_tab[i].p_occupied = FALSE;
  85.     return(TRUE);
  86. }
  87.